/*
 * @Date: 2023-08-07 15:45:52
 * @LastEditors: lyx
 * @LastEditTime: 2023-08-09 09:56:56
 * @FilePath: \sup-mini-app\src\components\Weather\model.ts
 * @Description:
 */

import { queryWeatherByLocation } from "@/services/weather";

export default {
  namespace: "weather",
  state: {
    weather: {},
  },
  effects: {
    *queryWeatherByLocation({ payload }: any, { call, put }: any) {
      const res = yield call(queryWeatherByLocation, payload);
      if (res.status) {
        yield put({
          type: "save",
          payload: {
            weather: res.content,
          },
        });
        return res.content;
      }
    },
  },
  reducers: {
    save(state, { payload }) {
      return { ...state, ...payload };
    },
  },
};
